import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { MsgManager } from "../../../manager/MsgManager";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
type int = number;
//class InputMoneyWindow
    
    export  class InputMoneyWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.init();
            return;
        }

        public updateDisplayerList(arg1: string): void
        {
            if (arg1 != this.CONTRIBUTE_GOLD) 
            {
                if (arg1 == this.CONTRIBUTE_COIN) 
                {
                    if (this.contains(this._goldBitmap)) 
                    {
                        this.removeChild(this._goldBitmap);
                    }
                    if (this.contains(this._coinBitmap) == false) 
                    {
                        this.addChild(this._coinBitmap);
                    }
                    this._tipText.htmlText = Language.getString(57651);
                }
            }
            else 
            {
                if (this.contains(this._coinBitmap)) 
                {
                    this.removeChild(this._coinBitmap);
                }
                if (this.contains(this._goldBitmap) == false) 
                {
                    this.addChild(this._goldBitmap);
                }
                this._tipText.htmlText = Language.getString(57650);
            }
            if (this._moneyInput) 
            {
                this._moneyInput.name = arg1;
            }
            return;
        }

        public updateMomeyText(arg1: int): void
        {
            this._moneyInput.text = arg1.toString();
            return;
        }

        public get coin(): int
        {
            this._coin = int(this._moneyInput.text);
            return this._coin;
        }

        public get gold(): int
        {
            this._gold = int(this._moneyInput.text);
            return this._gold;
        }

        public set maxGold(arg1: int)
        {
            this._maxGold = arg1;
            return;
        }

        public set maxCoin(arg1: int)
        {
            this._maxCoin = arg1;
            return;
        }

        public set callBackFun(arg1: Function)
        {
            this._callBackFun = arg1;
            return;
        }

        /* internal  */init(): void
        {
            titleHeight = 30;
            this.setSize(248, 140);
            this.title = Language.getString(52015);
            this._moneyInput = ObjCreate.createGTextInput(33, 50, 178, 20, this);
            this._moneyInput.restrict = "0-9";
            this._moneyInput.maxChars = 8;
            this._moneyInput.text = "0";
            this._moneyInput.addEventListener(flash.events.Event.CHANGE, this.onMoneyChangeHandler);
            this._goldBitmap = GlobalClass.getBitmap("Yuanbao");
            this._goldBitmap.x = 185;
            this._goldBitmap.y = 50;
            this._coinBitmap = GlobalClass.getBitmap("Tongqian");
            this._coinBitmap.x = 187;
            this._coinBitmap.y = 50;
            this._tipText = ObjCreate.createTextField("", 17, 79, 220, 20, this, null, true);
            this._okBtn = new GButton();
            this._okBtn.label = Language.getString(52012);
            this._okBtn.styleName = "Button";
            this._okBtn.setSize(46, 27);
            this._okBtn.move(54, 100);
            this._okBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOkBtnClickHandler);
            this.addChild(this._okBtn);
            this._cancelBtn = new GButton();
            this._cancelBtn.label = Language.getString(52013);
            this._cancelBtn.styleName = "Button";
            this._cancelBtn.setSize(46, 27);
            this._cancelBtn.move(144, 100);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnClickHandler);
            this.addChild(this._cancelBtn);
            return;
        }

        /* internal  */onOkBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._moneyInput.name != this.CONTRIBUTE_GOLD) 
            {
                if (this._moneyInput.name == this.CONTRIBUTE_COIN) 
                {
                    if (this.coin < 5000) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(57653));
                        this.updateMomeyText(5000);
                        return;
                    }
                }
            }
            else if (this.gold < 10) 
            {
                MsgManager.showRollTipsMsg(Language.getString(57652));
                this.updateMomeyText(10);
                return;
            }
            if (this._callBackFun != null) 
            {
                this._callBackFun(true, this.gold, this.coin);
            }
            this.onCancelBtnClickHandler(null);
            return;
        }

        /* internal  */onCancelBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        /* internal  */onMoneyChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (arg1.target.name != this.CONTRIBUTE_GOLD) 
            {
                if (arg1.target.name == this.CONTRIBUTE_COIN) 
                {
                    if (this.coin >= 5000 && this.coin <= this._maxCoin) 
                    {
                        this.updateMomeyText(this.coin);
                    }
                    else if (this.coin > this._maxCoin) 
                    {
                        this.updateMomeyText(this._maxCoin);
                    }
                }
            }
            else if (this.gold >= 10 && this.gold <= this._maxGold) 
            {
                this.updateMomeyText(this.gold);
            }
            else if (this.gold > this._maxGold) 
            {
                this.updateMomeyText(this._maxGold);
            }
            return;
        }

        public /* const */CONTRIBUTE_GOLD: string="contribute_gold";

        public /* const */CONTRIBUTE_COIN: string="contribute_coin";

        /* internal */ /* var */_moneyInput: GTextInput;

        /* internal */ /* var */_tipText: Object /* flash.text.TextField */;

        /* internal */ /* var */_goldBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_coinBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_okBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_coin: int;

        /* internal */ /* var */_gold: int;

        /* internal */ /* var */_maxGold: int;

        /* internal */ /* var */_maxCoin: int;

        /* internal */ /* var */_callBackFun: Function=null;
    }
